<template>
  <el-card>
    <el-form :inline="true" :model="state.queryForm" @keyup.enter="getDataList()">
      <el-form-item>
        <el-button type="primary" @click="addOrUpdateHandle()">新增</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="state.dataListLoading" :data="state.dataList" border style="width: 100%">
      <el-table-column prop="id" label="编号" header-align="center" align="center" width="200"></el-table-column>
      <el-table-column prop="name" label="课程名称" header-align="center" align="center"></el-table-column>
      <el-table-column prop="teacherName" label="教师" header-align="center" align="center"></el-table-column>
      <el-table-column prop="maxNum" label="可选人数" header-align="center" align="center"></el-table-column>
      <fastTableColumn prop="type" label="课程类型" dictType="course_type"></fastTableColumn>
<!--      <el-table-column prop="name" label="创建者" header-align="center" align="center"></el-table-column>-->
      <el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
        <template #default="scope">
          <el-button type="primary" link @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
          <el-button type="primary" link @click="deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update ref="addOrUpdateRef" @refresh-data-list="getDataList"></add-or-update>
  </el-card>
</template>

<script setup lang="ts">
import { useCrud } from '@/hooks'
import { reactive, ref } from 'vue'
import AddOrUpdate from './add-or-update.vue'
import { IHooksOptions } from '@/hooks/interface'
import fastTableColumn from "@/components/fast-table-column";

const state: IHooksOptions = reactive({
  dataListUrl: '/t/course/page',
  deleteUrl: '/t/course',
})

const addOrUpdateRef = ref()
const addOrUpdateHandle = (id?: string) => {
  addOrUpdateRef.value.init(id)
}

const { getDataList, deleteHandle } = useCrud(state)
</script>
